package com.yezong.AidMe.mapper;

import com.yezong.AidMe.entity.Order;
import com.yezong.AidMe.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Mapper
@Repository
public interface OrderMapper {

    @Select("select * from orderitem where id=#{id}")
    Order selectById(Integer id);

    @Select("select * from orderitem where title like concat('%',#{word},'%') or details  like concat('%',#{word},'%')")
    List<Order> selectByTitleAndDetails(@Param("word") String word);

    @Select("select * from orderitem where isborrowed=0")
    List<Order> selectAll();

    @Select("select * from orderitem where isborrowed=0 order by view desc")
    List<Order> selectByView();

    @Select("select * from orderitem where isborrowed=0 order by publishtime desc")
    List<Order> selectByPublishTime();

    @Select("select * from orderitem where isborrowed=0 and publishlocation like concat('%',#{location},'%') order by view desc")
    List<Order> selectByLocalView(String location);

    @Select("select * from orderitem where isborrowed=0 and publishlocation like concat('%',#{location},'%') order by publishtime desc")
    List<Order> selectByLocalPublishTime(String location);

    @Select("select * from orderitem where isborrowed=0 and type=#{type}")
    List<Order> selectByType(String type);

    @Insert("insert into orderitem(lid,bid,publishtime,publishlocation,lendtime,ddltime,isborrowed,isback,type,title,details,price,view) values(#{lid},#{bid},#{publishtime},#{publishlocation},#{lendtime},#{ddltime},#{isborrowed},#{isback},#{type},#{title},#{details},#{price},#{view}")
    Integer insertOrder(Order order);

    @Update("update orderitem set lid=#{lid},bid=#{bid},publishtime=#{publishtime},publishlocation=#{publishlocation},lendtime=#{lendtime},ddltime=#{ddltime},isborrowed=#{isborrowed},isback=#{isback},type=#{type},title=#{title},details=#{details},price=#{price},view=#{view} where id = #{id}")
    Integer updateOrder(Order order, Integer id);

    @Delete("delete from orderitem where id=#{id}")
    Integer deleteOrder(Integer id);

}
